package com.qymerge.manage.core.utils;

import com.qymerge.manage.core.bean.HttpResDTO;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Desc httpclient操作工具类
 */
public class HttpRequestUtil {

    private static String CHARSET_ENCODING = "UTF-8";
    private static int TIMEOUT = 10000;
    private static String USER_AGENT = "Mozilla/4.0 (compatible; MSIE 7.0; Win32)";

    /**
     * 获取DefaultHttpClient对象
     *
     * @param charset
     * @return
     */
    private static DefaultHttpClient getDefaultHttpClient(final String charset) {
        return getDefaultHttpClient(charset, TIMEOUT);
    }

    /**
     * 获取DefaultHttpClient对象
     *
     * @param timeout
     * @return
     */
    private static DefaultHttpClient getDefaultHttpClient(final int timeout) {
        return getDefaultHttpClient(CHARSET_ENCODING, timeout);
    }

    /**
     * 获取DefaultHttpClient对象
     *
     * @param charset
     * @return
     */
    private static DefaultHttpClient getDefaultHttpClient(final String charset, final int timeout) {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        String ua = USER_AGENT;
        // 模拟浏览器，解决一些服务器程序只允许浏览器访问的问题
        httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, ua);
        httpclient.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
        httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset == null ? CHARSET_ENCODING : charset);

        // 浏览器兼容性
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
        // 定义重试策略
        httpclient.setHttpRequestRetryHandler(requestRetryHandler);

        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);

//        String host = "220.73.173.111";
//        int port = 80;
        //此代理不保证你看到的时候还存活
//        HttpHost proxy = new HttpHost(host, port);
//        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
//
//        System.out.println(ua);
//        System.out.println(host + port);
        //如果代理要认证，则加上以下语句
//        httpclient.getCredentialsProvider().setCredentials(new AuthScope("proxy adress", proxy port),
//                new UsernamePasswordCredentials("username", "password"));

        return httpclient;
    }

    /**
     * 访问https的网站
     *
     * @param httpclient
     */
    private static void enableSSL(DefaultHttpClient httpclient) {
        // 调用ssl
        try {
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, new TrustManager[]{truseAllManager}, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
            sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            Scheme https = new Scheme("https", sf, 443);
            httpclient.getConnectionManager().getSchemeRegistry().register(https);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 重写验证方法，取消检测ssl
     */
    private static TrustManager truseAllManager = new X509TrustManager() {
        public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException {
        }

        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };

    /**
     * 异常自动恢复处理, 使用HttpRequestRetryHandler接口实现请求的异常恢复
     */
    private static HttpRequestRetryHandler requestRetryHandler = new HttpRequestRetryHandler() {
        // 自定义的恢复策略
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            // 设置恢复策略，在发生异常时候将自动重试3次 v1.0
            // 禁用重试功能 executionCount=2 禁用重试功能
            if (executionCount >= 3) {
                // 如果连接次数超过了最大值则停止重试
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                // 如果服务器连接失败重试
                return true;
            }
            if (exception instanceof SSLHandshakeException) {
                // 不要重试ssl连接异常
                return false;
            }
            HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            boolean idempotent = (request instanceof HttpEntityEnclosingRequest);
            if (!idempotent) {
                // 重试，如果请求是考虑幂等
                return true;
            }
            return false;
        }
    };

    /**
     * 使用ResponseHandler接口处理响应，HttpClient使用ResponseHandler会自动管理连接的释放，解决了对连接的释放管理
     */
    private static ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
        // 自定义响应处理
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                String charset = EntityUtils.getContentCharSet(entity) == null ? CHARSET_ENCODING : EntityUtils.getContentCharSet(entity);
                return new String(EntityUtils.toByteArray(entity), charset);
            } else {
                return null;
            }
        }
    };


    /**
     * GET方式提交
     *
     * @param url
     * @return
     */
    public static String requestGet(String url) {
        return requestGet(url, null, null, TIMEOUT);
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList) {
        return requestGet(url, paramsList, null, TIMEOUT);
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @param timeout
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList, int timeout) {
        return requestGet(url, paramsList, null, timeout);
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @param proxy
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList, HttpHost proxy) {
        return requestGet(url, paramsList, proxy, TIMEOUT);
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @param headerList
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList, List<NameValuePair> headerList) {
        return requestGet(url, paramsList, null, 0, headerList);
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @param headerList
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList, HttpHost proxy, int timeout, List<NameValuePair> headerList) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, timeout == 0 ? TIMEOUT : timeout);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 将参数进行utf-8编码
        if (null != paramsList && paramsList.size() > 0) {
            formatParams = URLEncodedUtils.format(paramsList, CHARSET_ENCODING);
        }
        // 如果代理对象不为空则设置代理
        if (null != proxy) {
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        }
        HttpRequestBase hrb = null;
        try {
            if (formatParams != null) {
                url = (url.indexOf("?")) < 0 ? (url + "?" + formatParams) : (url.substring(0, url.indexOf("?") + 1) + formatParams);
            }
            HttpGet hg = new HttpGet(url);
            if (headerList != null) {
                for (NameValuePair header : headerList) {
                    hg.setHeader(header.getName(), header.getValue());
                }
            }
            HttpResponse response = httpclient.execute(hg);
            result = parseResult(response);
            hrb = hg;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }

    /**
     * GET方式提交
     *
     * @param url
     * @param paramsList
     * @param proxy
     * @param timeout
     * @return
     */
    public static String requestGet(String url, List<NameValuePair> paramsList, HttpHost proxy, int timeout) {
        return requestGet(url, paramsList, proxy, timeout, new ArrayList<NameValuePair>());
    }


    /**
     * 表单参数提交
     *
     * @param url
     * @param timeout
     * @return
     */
    public static String requestPostForm(String url, int timeout) {
        return requestPostForm(url, null, null, timeout);
    }

    /**
     * 表单参数提交
     *
     * @param url
     */
    public static String requestPostForm(String url) {
        return requestPostForm(url, null, null, TIMEOUT);
    }

    /**
     * @param url
     */
    public static String requestPostForm(String url, List<NameValuePair> paramsList) {
        return requestPostForm(url, paramsList, null, TIMEOUT);
    }

    /**
     * 表单参数提交
     *
     * @param url
     */
    public static String requestPostForm(String url, List<NameValuePair> paramsList, HttpHost proxy) {
        return requestPostForm(url, paramsList, proxy, TIMEOUT);
    }

    /**
     * 表单参数提交
     *
     * @param url
     */
    public static String requestPostForm(String url, List<NameValuePair> paramsList, int timeout) {
        return requestPostForm(url, paramsList, null, timeout);
    }

    /**
     * 表单参数提交
     *
     * @param url
     * @param paramsList
     * @param proxy
     * @param timeout
     * @return
     */
    public static String requestPostForm(String url, List<NameValuePair> paramsList, HttpHost proxy, int timeout) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, timeout);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 将参数进行utf-8编码
        if (null != paramsList && paramsList.size() > 0) {
            formatParams = URLEncodedUtils.format(paramsList, CHARSET_ENCODING);
        }
        // 如果代理对象不为空则设置代理
        if (null != proxy) {
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        HttpRequestBase hrb = null;
        try {
            HttpPost hp = new HttpPost(url);
            //拼接好的表单参数
            if (formatParams != null) {
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramsList, CHARSET_ENCODING);
                entity.setContentType(ContentType.MULTIPART_FORM_DATA.getMimeType());
                hp.setEntity(entity);
            }
            HttpResponse response = httpclient.execute(hp);
            result = parseResult(response);
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }

    /**
     * 表单参数提交
     *
     * @param url
     * @param paramsList
     * @return
     */
    public static String requestPost(String url, List<NameValuePair> paramsList) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, TIMEOUT);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 将参数进行utf-8编码
        if (null != paramsList && paramsList.size() > 0) {
            formatParams = URLEncodedUtils.format(paramsList, CHARSET_ENCODING);
        }
        // 如果代理对象不为空则设置代理
//        if (null != proxy) {
//            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
//        }
        HttpRequestBase hrb = null;
        try {
            HttpPost hp = new HttpPost(url);
            //拼接好的表单参数
            if (formatParams != null) {
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramsList, CHARSET_ENCODING);
//                entity.setContentType(ContentType.MULTIPART_FORM_DATA.getMimeType());
                hp.setEntity(entity);
            }
            HttpResponse response = httpclient.execute(hp);
            result = parseResult(response);
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }

    public static String requestPost(String url, List<NameValuePair> paramsList, Map<String, Object> multipartMap) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, TIMEOUT);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 将参数进行utf-8编码
        if (null != paramsList && paramsList.size() > 0) {
            formatParams = URLEncodedUtils.format(paramsList, CHARSET_ENCODING);
        }
        // 如果代理对象不为空则设置代理
//        if (null != proxy) {
//            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
//        }
        HttpRequestBase hrb = null;
        try {
            HttpPost hp = new HttpPost(url);
            //拼接好的表单参数
            if (formatParams != null) {
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramsList, CHARSET_ENCODING);
//                entity.setContentType(ContentType.MULTIPART_FORM_DATA.getMimeType());
                hp.setEntity(entity);
            }

            if (multipartMap != null) {
                MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                for (String key : multipartMap.keySet()) {
                    if (multipartMap.get(key) instanceof String) {
                        builder.addTextBody(key, multipartMap.get(key).toString());
                    }
                    if (multipartMap.get(key) instanceof File) {
                        builder.addPart(key, new FileBody((File) multipartMap.get(key)));
                    }
                }
                hp.setEntity(builder.build());
            }

            HttpResponse response = httpclient.execute(hp);
            result = parseResult(response);
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }

    /**
     * 表单参数提交
     *
     * @param url
     * @param paramsList
     * @param timeout
     * @return
     */
    public static String postForm(String url, List<NameValuePair> paramsList, List<NameValuePair> headerList, int timeout) {
        HttpResDTO entity = postForm(url, paramsList, headerList, null, timeout);
        if (entity == null) {
            return "";
        }
        return entity.getBody();
    }

    /**
     * 表单参数提交
     *
     * @param url
     * @param paramsList
     * @param proxy
     * @param timeout
     * @return
     */
    public static HttpResDTO postForm(String url, List<NameValuePair> paramsList, List<NameValuePair> headerList, HttpHost proxy, int timeout) {
        HttpResDTO resEntity = new HttpResDTO();
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, timeout);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 将参数进行utf-8编码
        if (null != paramsList && paramsList.size() > 0) {
            formatParams = URLEncodedUtils.format(paramsList, CHARSET_ENCODING);
        }
        // 如果代理对象不为空则设置代理
        if (null != proxy) {
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        HttpRequestBase hrb = null;
        try {
            HttpPost hp = new HttpPost(url);
            if (headerList != null) {
                for (NameValuePair header : headerList) {
                    hp.setHeader(new BasicHeader(header.getName(), header.getValue()));
                }
            }
            //拼接好的表单参数
            if (formatParams != null) {
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramsList, CHARSET_ENCODING);
                entity.setContentType(ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
                hp.setEntity(entity);
            }
            HttpResponse response = httpclient.execute(hp);
            resEntity.setStatus(response.getStatusLine().getStatusCode());
            Map headers = new HashMap();
            for (Header header : response.getAllHeaders()) {
                headers.put(header.getName(), header.getValue());
            }
            resEntity.setHeaders(headers);
            resEntity.setBody(parseResult(response));
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return resEntity;
    }


    /**
     * body参数提交
     *
     * @param url
     * @param paramsJson
     * @return
     */
    public static String requestPostBody(String url, String paramsJson, List<NameValuePair> headers) {
        return requestPostBody(url, paramsJson, null, TIMEOUT, headers);
    }

    /**
     * body参数提交
     *
     * @param url
     * @param paramsJson
     * @return
     */
    public static String requestPostBody(String url, String paramsJson) {
        return requestPostBody(url, paramsJson, null, TIMEOUT, null);
    }

    /**
     * body参数提交
     *
     * @param url
     * @param paramsJson
     * @param proxy
     * @return
     */
    public static String requestPostBody(String url, String paramsJson, HttpHost proxy) {
        return requestPostBody(url, paramsJson, proxy, TIMEOUT, null);
    }

    /**
     * body参数提交
     *
     * @param url
     * @param paramsJson
     * @param proxy
     * @param timeout
     * @return
     */
    public static String requestPostBody(String url, String paramsJson, HttpHost proxy, int timeout, List<NameValuePair> headList) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, timeout);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        // 如果代理对象不为空则设置代理
        if (null != proxy) {
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        HttpRequestBase hrb = null;
        try {
            HttpPost hp = new HttpPost(url);
            if (headList != null) {
                for (final NameValuePair nameValuePair : headList) {
                    hp.setHeader(nameValuePair.getName(), nameValuePair.getValue());
                }
            }
            //拼接好的表单参数
            if (paramsJson != null) {
                HttpEntity entity = new StringEntity(paramsJson, ContentType.APPLICATION_JSON.getMimeType(), CHARSET_ENCODING);
                hp.setEntity(entity);
            }
            HttpResponse response = httpclient.execute(hp);
            result = parseResult(response);
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }


    /**
     * body参数提交
     *
     * @param url
     * @param paramsJson
     * @return
     */
    public static String requestPutBody(String url, String paramsJson, List<NameValuePair> headList) {
        String result = null;
        // 判断输入的值是是否为空
        if (null == url || "".equals(url)) {
            return null;
        }
        // 创建HttpClient实例
        DefaultHttpClient httpclient = getDefaultHttpClient(CHARSET_ENCODING, TIMEOUT);

        // 判断是否是https请求
        if (url.startsWith("https")) {
            enableSSL(httpclient);
        }
        String formatParams = null;
        HttpRequestBase hrb = null;
        try {
            HttpPut hp = new HttpPut(url);
            if (headList != null) {
                for (final NameValuePair nameValuePair : headList) {
                    hp.setHeader(nameValuePair.getName(), nameValuePair.getValue());
                }
            }
            //拼接好的表单参数
            if (paramsJson != null) {
                HttpEntity entity = new StringEntity(paramsJson, ContentType.APPLICATION_JSON.getMimeType(), CHARSET_ENCODING);
                hp.setEntity(entity);
            }
            HttpResponse response = httpclient.execute(hp);
            result = parseResult(response);
            hrb = hp;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //释放连接
            abortConnection(hrb, httpclient);
        }
        return result;
    }

    /**
     * 从响应域中解析响应的详细内容
     *
     * @param response
     * @return
     * @throws IllegalStateException
     * @throws IOException
     */
    private static String parseResult(HttpResponse response) throws IllegalStateException, IOException {
        String content = "";
        if (response == null) {
            return content;
        }
        HttpEntity entry = response.getEntity();
        if (entry == null) {
            return content;
        }
        return EntityUtils.toString(entry, CHARSET_ENCODING);
    }

    /**
     * 释放HttpClient连接
     *
     * @param hrb        请求对象
     * @param httpclient client对象
     */
    private static void abortConnection(HttpRequestBase hrb, final HttpClient httpclient) {
        if (hrb != null) {
            hrb.abort();
        }
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }

    public static void main(String[] args) throws URISyntaxException {
//        System.out.println(new Date());
//        String url_rank = "http://api.busdh.com/market-api/game/recommend";
//        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//        nameValuePairs.add(new BasicNameValuePair("page", "1"));
//        nameValuePairs.add(new BasicNameValuePair("size", "1"));
////        String result = HttpClientUtil.requestGet(url_rank, nameValuePairs);
//
//        String result = HttpRequestUtil.requestPostForm(url_rank, nameValuePairs);
//
//        System.out.println(result);
//        System.out.println(new Date());

//        String url = "http://business.skyscanner.net/apiservices/pricing/v1.0/?apikey=prtl6749387986743898559646983194";
//        url = "http://business.skyscanner.net/apiservices/pricing/v1.0/54462c7b32a7475fb042a35859606f07_ecilpojl_6DEE38DD6B1FEFC71F688999EA4D59D6?apikey=prtl6749387986743898559646983194&pagesize=2&pageindex=0";
        //url = "http://partners.api.skyscanner.net/apiservices/autosuggest/v1.0/CN/CNY/zh-CN?query=%E6%9D%AD%E5%B7%9E&apiKey=prtl6749387986743898559646983194";
//        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//        nameValuePairs.add();
//        HttpResEntity entity = postForm(url,nameValuePairs,null,0);
//        System.out.println(entity);

//        System.out.println(requestPostBody("http://127.0.0.1:9999/paySuccessByEmail","sb"));

//        String queryUrl = "http://115.182.19.34/discover/indexPage?appv=3.9.8&ch=AppStore_3.9.8.6&did=25254106ddecde731c3439586bce4f80&dt=iPhone6%2C2&im=F65644B7-676F-4BF1-AF89-726A632E73FF&la=cn&latitude=31.173983&lm=weixin&longitude=121.402019&lp=-1.000000&net=0-0-wifi&osn=iOS&osv=8.2&seid=e495d243b3b13b0a1e5feb8c2ae5f1c6&sh=568.000000&sw=320.000000&token=VAnyN5eP-QTjJBz4JiU5PF-YBFcEwPQ9&tpid=discover&ts=1461917762515";
//
//        String res = requestPostBody(queryUrl, "{\"nextkey\":\"10\",\"token\":\"VAnyN5eP-QTjJBz4JiU5PF-YBFcEwPQ9\"}");

//        String wxArticleUrl = "http://mp.weixin.qq.com/s?src=3&timestamp=1467772933&ver=1&signature=DydhptiJ9zoLcs*9I40e9JGsV1rXNUjasY2nq5XUDh3PMjBahL6sAh61HDzW6TgY4YtJdDRIQOla0R5*VsxW*pASeP2m0zndFNMTXG8FyW3zb4k9E1eikVUYK2sbB5M17290kxXQUz3Nob0cJB2hNqUVQWWPbiOdZ-cESerRYAE=";
//
//        String res = requestGet(wxArticleUrl);
//
//        System.out.println(res);

//        System.out.println(new Random().nextInt(1000));

//        extractSetTopTag();

    }


}
